import 'dart:io';

import 'package:bwt_ad_flutter/BwtAdCore.dart';
import 'package:bwt_ad_flutter/ad/widget/nativeWidget/BwtNativeAd.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';

class BwtNativeAdWidget extends StatefulWidget {
  final BwtNativeAd bwtNativeAd;
  final String viewType;
  const BwtNativeAdWidget(
      {super.key, required this.bwtNativeAd, required this.viewType});

  @override
  State<BwtNativeAdWidget> createState() => _BwtNativeAdWidgetState();
}

class _BwtNativeAdWidgetState extends State<BwtNativeAdWidget> {
  @override
  Widget build(BuildContext context) {
    var creationParams = {
      BwtAdCore.keyAdLoaderId: widget.bwtNativeAd.adLoaderId,
      BwtAdCore.keyAdId: widget.bwtNativeAd.adId,
      BwtAdCore.keyAdWidth: widget.bwtNativeAd.adWidth,
      BwtAdCore.keyAdHeight: widget.bwtNativeAd.adHeight,
    };
    return Container(
      width: widget.bwtNativeAd.adWidth,
      height: widget.bwtNativeAd.adHeight,
      constraints: BoxConstraints(maxWidth: widget.bwtNativeAd.adWidth),
      child: Platform.isAndroid
          ? AndroidView(
              viewType: widget.viewType,
              creationParams: creationParams,
              creationParamsCodec: const StandardMessageCodec(),
            )
          : UiKitView(
              viewType: widget.viewType,
              creationParams: creationParams,
              creationParamsCodec: const StandardMessageCodec(),
            ),
    );
  }
}
